#ifndef COMMANDRUNNER_H
#define COMMANDRUNNER_H

#include <QObject>
#include <QTimer>
#include <QThreadPool>
#include <QRunnable>

class DatabaseManager;

// 命令执行任务类
class CommandTask : public QRunnable
{
public:
    CommandTask(const QString &commandId, 
                const QString &command, 
                const QString &folderId, 
                const QString &filePath, 
                const QString &params,
                DatabaseManager *databaseManager);
    
    void run() override;

private:
    QString m_commandId;
    QString m_command;
    QString m_folderId;
    QString m_filePath;
    QString m_params;
    DatabaseManager *m_databaseManager;
    
    void executeCommand();
};

// 命令运行器类
class CommandRunner : public QObject
{
    Q_OBJECT

public:
    explicit CommandRunner(QObject *parent = nullptr);
    ~CommandRunner();
    
    // 设置数据库管理器
    void setDatabaseManager(DatabaseManager *databaseManager);
    
    // 启动命令运行器
    void start();
    
    // 停止命令运行器
    void stop();
    
    // 设置线程池大小
    void setThreadPoolSize(int size);

private slots:
    void checkPendingCommands();

private:
    DatabaseManager *m_databaseManager;
    QTimer *m_timer;
    QThreadPool *m_threadPool;
    int m_threadPoolSize;
    
    void processPendingCommands();
};

#endif // COMMANDRUNNER_H

